
class LuaConvert:
    def __init__(self, tab, line):
        self._tab = tab
        self._line = line
            
    def convert(self, data):
        return self._convert_value(data, 1)
    
    def _convert_key(self, key):
        if type(key) == str:
            return f'["{key}"]'
        elif type(key) == int:
            return f'[{key}]'
        else:
            raise ValueError(f"unsupported key type: {type(key)}")

    def _convert_value(self, value, indent = 0):
        tab = self._tab
        indent_str = tab * indent
        line = self._line
        if type(value) == str:
            return f'"{value}"'
        elif type(value) == int:
            return f'{value}'
        elif type(value) == dict:
            value_str = '{' + line
            for key, val in value.items():
                value_str += f'{indent_str}{self._convert_key(key)} = {self._convert_value(val, indent+1)}, {line}'
            value_str += tab*(indent-1) + '}'
            return value_str
        elif type(value) in (list, set, tuple):
            value_str = '{' + line
            for val in value:
                value_str += f'{indent_str}{self._convert_value(val, indent+1)}, {line}'
            value_str += tab*(indent-1) + '}'
            return value_str        